/*java jdk 1.7+
# -*- coding: utf-8 -
'''
Created on 2022年6月15日
@author: zxyong 13738196011
'''*/

package com.plugins.usereflect;

import java.sql.SQLException;
import java.util.Enumeration;
import java.util.LinkedHashMap;

import org.json.JSONArray;
import org.json.JSONObject;

import com.zxy.business.Ope_DB_Cent;
import com.zxy.common.Com_Para;
import com.zxy.common.Db_Common_InterFace;
import com.zxy.common.PooledConnection_InterFace;
import com.zxy.db1.DBManager1;
import com.zxy.db1.PooledConnection1;
import com.zxy.db10.DBManager10;
import com.zxy.db10.PooledConnection10;
import com.zxy.db2.DBManager2;
import com.zxy.db2.PooledConnection2;
import com.zxy.db3.DBManager3;
import com.zxy.db3.PooledConnection3;
import com.zxy.db4.DBManager4;
import com.zxy.db4.PooledConnection4;
import com.zxy.db5.DBManager5;
import com.zxy.db5.PooledConnection5;
import com.zxy.db6.DBManager6;
import com.zxy.db6.PooledConnection6;
import com.zxy.db7.DBManager7;
import com.zxy.db7.PooledConnection7;
import com.zxy.db8.DBManager8;
import com.zxy.db8.PooledConnection8;
import com.zxy.db9.DBManager9;
import com.zxy.db9.PooledConnection9;

//数据库操作demo
public class A01_INFSCH_IN implements com.zxy.common.ParamName_InterFace
{
	public StringBuilder	strResult		= new StringBuilder();
	public String			user_main_id			= null;
	public String			session_id		= null;
	public String			param_name		= "";
	// 库名 为空则获取库信息，不为空则获取对应库表信息
	public String			param_value1	= null;
	// 表或视图 0:表 1:视图
	public String			param_value2	= null;
	public String			param_value3	= null;
	public String			param_value4	= null;
	public String			param_value5	= null;
	public String			param_value6	= null;
	public String			param_value7	= null;
	public String			param_value8	= null;
	public String			param_value9	= null;
	public String			param_value10	= null;

	public void init_start()
	{
		java.sql.ResultSet rs = null;
		StringBuilder sqlException = null;
		PooledConnection_InterFace pi = null;
		Db_Common_InterFace dbc = null;

		// 判断表库中是否存在
		try
		{
			JSONObject jsoResult = new JSONObject(new LinkedHashMap());
			JSONArray jsary = new JSONArray();
			String DB_CN_NAME = "";
			String DB_MAIN_ID = "";
			Ope_DB_Cent odc = new Ope_DB_Cent();
			for(Enumeration<String> sm = Com_Para.htDb.keys();sm.hasMoreElements();)
			{
				String DB_EN_NAME = "";
				JSONObject jsoSchema = new JSONObject(new LinkedHashMap());
				String key = sm.nextElement();

				// 根据不同数据源获取通用数据库调用方法
				try
				{
					Object dbcobject = odc.Get_Db_Common(Integer.valueOf(key));
					dbc = (Db_Common_InterFace) (odc.Obj_To_Db_Common(dbcobject));
					rs = dbc.Common_Sql(new StringBuilder("select 1"));
					sqlException = dbc.getSqlException();
					pi = (PooledConnection_InterFace) dbc.getConn_a();
					DB_EN_NAME = pi.getConnection().getCatalog();
				}
				catch(Exception es)
				{

				}
				finally
				{
					try
					{
						if(!java.util.Objects.equals(rs,null))
						{
							rs.getStatement().close();
							rs.close();
						}
						if(!java.util.Objects.equals(dbc,null) && !pi.isB_nocursor())
						{
							if(!java.util.Objects.equals(pi,null)
									&& !java.util.Objects.equals(pi.getCalls(),null))
								pi.getCalls().close();
						}else if(!java.util.Objects.equals(dbc,null))
						{
							pi.returnConnection();
						}
					}
					catch(SQLException e)
					{
					}
				}
				jsoSchema.put("MAIN_ID",key);
				jsoSchema.put("DB_MAIN_ID",key);
				jsoSchema.put("CN_NAME",Com_Para.htDb.get(key).getDB_CN_NAME());
				if(java.util.Objects.equals(this.param_value1,""))
				{
					this.param_value1 = DB_EN_NAME;
					DB_CN_NAME = Com_Para.htDb.get(key).getDB_CN_NAME();
					DB_MAIN_ID = key;
				}else if(java.util.Objects.equals(this.param_value1,key))
				{
					this.param_value1 = DB_EN_NAME;
					DB_CN_NAME = Com_Para.htDb.get(key).getDB_CN_NAME();
					DB_MAIN_ID = key;
				}
				jsary.put(jsoSchema);
			}
			jsoResult.put("DB_ID",jsary);
			StringBuilder strSql = new StringBuilder();
			if(java.util.Objects.equals(this.param_value2,"0")
					|| java.util.Objects.equals(this.param_value2,""))
			{
				strSql.append("select TABLE_NAME,'0' as TABLE_TYPE,'"
						+ DB_CN_NAME
						+ "' as DB_CN_NAME,"+DB_MAIN_ID+" as 'DB_MAIN_ID' FROM information_schema.`TABLES` "
						+ "where TABLE_SCHEMA='" + this.param_value1
						+ "' and TABLE_TYPE = 'BASE TABLE'");
			}else if(java.util.Objects.equals(this.param_value2,"1"))
			{
				strSql.append("select TABLE_NAME,'1' as TABLE_TYPE,'"
						+ DB_CN_NAME
						+ "' as DB_CN_NAME,"+DB_MAIN_ID+" as 'DB_MAIN_ID' FROM information_schema.`VIEWS` "
						+ "where TABLE_SCHEMA='" + this.param_value1
						+ "' ");
			}else
			{
				strSql.append("select TABLE_NAME,'0' as TABLE_TYPE,'"
						+ DB_CN_NAME
						+ "' as DB_CN_NAME,"+DB_MAIN_ID+" as 'DB_MAIN_ID' FROM information_schema.`TABLES` "
						+ "where TABLE_SCHEMA='" + this.param_value1
						+ "' and TABLE_TYPE = 'BASE TABLE'");
			}
			jsoResult.put(this.param_name,odc.SqlToJson(1,strSql.toString()));
			this.strResult.append(jsoResult.toString());
		}
		catch(Exception e)
		{
		}
	}

	/**
	 * @return strResult
	 */
	public StringBuilder getStrResult()
	{
		return strResult;
	}

	/**
	 * @param strResult
	 *            要设置的 strResult
	 */
	public void setStrResult(StringBuilder strResult)
	{
		this.strResult = strResult;
	}

	/**
	 * @return user_main_id
	 */
	public String getUser_main_id()
	{
		return user_main_id;
	}

	/**
	 * @param user_main_id
	 *            要设置的 user_main_id
	 */
	public void setUser_main_id(String user_main_id)
	{
		this.user_main_id = user_main_id;
	}

	/**
	 * @return session_id
	 */
	public String getSession_id()
	{
		return session_id;
	}

	/**
	 * @param session_id
	 *            要设置的 session_id
	 */
	public void setSession_id(String session_id)
	{
		this.session_id = session_id;
	}

	/**
	 * @return param_name
	 */
	public String getParam_name()
	{
		return param_name;
	}

	/**
	 * @param param_name
	 *            要设置的 param_name
	 */
	public void setParam_name(String param_name)
	{
		this.param_name = param_name;
	}

	/**
	 * @return param_value1
	 */
	public String getParam_value1()
	{
		return param_value1;
	}

	/**
	 * @param param_value1
	 *            要设置的 param_value1
	 */
	public void setParam_value1(String param_value1)
	{
		this.param_value1 = param_value1;
	}

	/**
	 * @return param_value2
	 */
	public String getParam_value2()
	{
		return param_value2;
	}

	/**
	 * @param param_value2
	 *            要设置的 param_value2
	 */
	public void setParam_value2(String param_value2)
	{
		this.param_value2 = param_value2;
	}

	/**
	 * @return param_value3
	 */
	public String getParam_value3()
	{
		return param_value3;
	}

	/**
	 * @param param_value3
	 *            要设置的 param_value3
	 */
	public void setParam_value3(String param_value3)
	{
		this.param_value3 = param_value3;
	}

	/**
	 * @return param_value4
	 */
	public String getParam_value4()
	{
		return param_value4;
	}

	/**
	 * @param param_value4
	 *            要设置的 param_value4
	 */
	public void setParam_value4(String param_value4)
	{
		this.param_value4 = param_value4;
	}

	/**
	 * @return param_value5
	 */
	public String getParam_value5()
	{
		return param_value5;
	}

	/**
	 * @param param_value5
	 *            要设置的 param_value5
	 */
	public void setParam_value5(String param_value5)
	{
		this.param_value5 = param_value5;
	}

	/**
	 * @return param_value6
	 */
	public String getParam_value6()
	{
		return param_value6;
	}

	/**
	 * @param param_value6
	 *            要设置的 param_value6
	 */
	public void setParam_value6(String param_value6)
	{
		this.param_value6 = param_value6;
	}

	/**
	 * @return param_value7
	 */
	public String getParam_value7()
	{
		return param_value7;
	}

	/**
	 * @param param_value7
	 *            要设置的 param_value7
	 */
	public void setParam_value7(String param_value7)
	{
		this.param_value7 = param_value7;
	}

	/**
	 * @return param_value8
	 */
	public String getParam_value8()
	{
		return param_value8;
	}

	/**
	 * @param param_value8
	 *            要设置的 param_value8
	 */
	public void setParam_value8(String param_value8)
	{
		this.param_value8 = param_value8;
	}

	/**
	 * @return param_value9
	 */
	public String getParam_value9()
	{
		return param_value9;
	}

	/**
	 * @param param_value9
	 *            要设置的 param_value9
	 */
	public void setParam_value9(String param_value9)
	{
		this.param_value9 = param_value9;
	}

	/**
	 * @return param_value10
	 */
	public String getParam_value10()
	{
		return param_value10;
	}

	/**
	 * @param param_value10
	 *            要设置的 param_value10
	 */
	public void setParam_value10(String param_value10)
	{
		this.param_value10 = param_value10;
	}
}
